package net.dgg.rz.production.controller;

import com.alibaba.fastjson.JSONObject;
import net.dgg.framework.tac.utils.DggDateUtil;
import net.dgg.framework.tac.utils.bean.DggRestResponse;
import net.dgg.framework.tac.utils.web.commmon.DggBaseController;
import net.dgg.iboss.base.util.CustomerNumberEncryptionUtil;
import net.dgg.iboss.base.util.DesUtil;
import net.dgg.iboss.base.util.JsonUtil;
import net.dgg.rz.common.constant.ModuleCodeConstant;
import net.dgg.rz.common.constant.ScProductConstant;
import net.dgg.rz.common.constant.SystemCommonConstant;
import net.dgg.rz.common.excption.CommonExcption;
import net.dgg.rz.common.service.CommonMangerExtService;
import net.dgg.rz.common.service.CommonService;
import net.dgg.rz.common.systemRecord.dao.SystemRecordDao;
import net.dgg.rz.common.systemRecord.entity.SystemRecord;
import net.dgg.rz.common.systemRecord.service.SystemRecordService;
import net.dgg.rz.common.utils.*;
import net.dgg.rz.production.dao.*;
import net.dgg.rz.production.entity.*;
import net.dgg.rz.production.entity.dto.OrderJsonDto;
import net.dgg.rz.production.entity.dto.ProductOrderDto;
import net.dgg.rz.production.entity.dto.WorkLoadDto;
import net.dgg.rz.production.exception.ProductOrderExcption;
import net.dgg.rz.production.service.AllOrderService;
import net.dgg.rz.production.service.ProductNodeService;
import net.dgg.rz.production.service.ProductOrderService;
import net.dgg.rz.production.service.ProductOrderWorkLoadService;
import net.dgg.tmd.foundation.platform.common.util.TranslateUtil;
import net.dgg.tmd.foundation.platform.role.service.RoleService;
import net.dgg.tmd.foundation.platform.session.SessionManager;
import net.dgg.tmd.foundation.platform.treebook.entity.TreeBook;
import net.dgg.tmd.foundation.platform.user.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/order_detail")
public class OrderDetailController extends DggBaseController {
    @Value("${ucApiUrl}")
    private String ucApiUrl;
    @Value("${orfApiUrl}")
    private String orfApiUrl;
    @Value("${bottomApiUrl}")
    private String bottomApiUrl;
    private final static String PATH_PREFIX = "/order_detail";
    @Autowired
    private ProductOrderDao productOrderDao;
    @Autowired
    private ProductOrderService productOrderService;
    @Autowired
    private ProductNodeService productNodeService;
    @Autowired
    private TranslateUtil translateUtil;
    @Autowired
    private DesUtil desUtil;
    @Autowired
    private SystemRecordService systemRecordService;
    @Autowired
    private SystemRecordDao systemRecordDao;
    @Autowired
    private OrderContactDao orderContactDao;
    @Autowired
    private ProductNodeOperatingDao productNodeOperatingDao;
    @Autowired
    private SessionManager sessionManager;
    @Autowired
    private OrderCustomerDao orderCustomerDao;
    @Autowired
    private OrderJsonDao orderJsonDao;
    @Autowired
    private OrderSubjectDao orderSubjectDao;
    @Autowired
    private CommonMangerExtService zzCommonMangerExtService;
    @Autowired
    private ProductOrderWorkLoadService productOrderWorkLoadService;
    @Autowired
    private DataPermissionUtils dataPermissionUtils;
    @Autowired
    private RoleService roleService;

    /**
     * 生产订单详情页
     *
     * @return
     */
    @RequestMapping("/index")
    public String index(@RequestParam Long scOrderId, String detailType, Model model) {
        UserEntity userEntity = sessionManager.getCurrentUser();
        model.addAttribute("ucApiUrl", ucApiUrl);
        model.addAttribute("orfApiUrl", orfApiUrl);
        model.addAttribute("bottomApiUrl",bottomApiUrl);
        ValidateUtils.strNotEmpty(scOrderId, CommonExcption.class, "生产子订单id不能为空");
        //订单信息
        ProductOrderDto order = productOrderDao.selectDtoByPrimaryKey(scOrderId);
        model.addAttribute("orderStauts", order.getStatus());
        model.addAttribute("orderPhone", order.getCustomerPhone());
        order.setStatus(translateUtil.translateCode(order.getStatus()));//翻译状态
        //判断订单来源是否是企大宝
        Boolean flag = false;
        if(null != order){
            if(SystemCommonConstant.QDS_SC.equals(order.getOrderSource())){
                flag = true;
            }
        }
        order.setOriginCode(translateUtil.translateCode(order.getOriginCode()));//翻译订单来源方式
        String[] hideColum = {"customerPhone"};//隐藏
        order.setCustomerPhone(desUtil.decrypt(order.getCustomerPhone()));//解密电话号码
        order = CustomerNumberEncryptionUtil.encryptionObject(hideColum, order);//隐藏电话号码
        model.addAttribute("order", order);
        //相关生产订单信息
        List<ProductOrder> relatedProductOrderList = productOrderDao.getListByOrderId(order.getOrderId(), null, order.getId());
        if (relatedProductOrderList != null && relatedProductOrderList.size() > 0) {
            relatedProductOrderList = translateUtil.translateList(new String[]{"status"}, relatedProductOrderList);
            model.addAttribute("relatedProductOrderList", relatedProductOrderList);
        }
        //申请审核记录
        Map params = new HashMap();
        params.put("workId", order.getId());
        int[] operateTypeArr = {6, 11, 28, 29, 30, 31};//6、退单 11、废单 28、退单审核通过 29、退单审核驳回 30、废单审核通过 31、废单审核驳回
        params.put("operateTypeArr", operateTypeArr);
        List<SystemRecord> systemRecords = systemRecordDao.findByParamsList(params);
        if (systemRecords != null && systemRecords.size() > 0) {
            for (SystemRecord systemRecord : systemRecords) {
                systemRecord.setOperateType(SystemRecord.operateTypeMap.get(systemRecord.getOperateType()));
            }
            model.addAttribute("auditLogs", systemRecords);
        }
        //借贷人信息
        List<OrderContact> orderContactList = orderContactDao.getListByOrderNo(order.getOrderNo());
        if (orderContactList != null && orderContactList.size() > 0) {
            for (OrderContact orderContact : orderContactList) {
                if (StringUtils.isNotEmpty(orderContact.getCardId())) {
                    orderContact.setCardId(IdCardUtil.hiddenIdCard(orderContact.getCardId()));
                }
            }
            //translateUtil.translateList(new String[]{"operateType"},systemRecords);
            String[] transColum = {"contactMaritalStatus", "relationshipOfCus"};
            orderContactList = translateUtil.translateList(transColum, orderContactList);
            String[] hideColums = {"no"};//隐藏
            orderContactList = desUtil.decryptList(hideColums, orderContactList);
            orderContactList = CustomerNumberEncryptionUtil.encryptionList(hideColums, orderContactList);
            model.addAttribute("orderContactList", orderContactList);
        }
        model.addAttribute("userEntityId", userEntity.getId());
        //查询婚姻状况
        List<TreeBook> maritalStatus = zzCommonMangerExtService.queryTreeBookListByCode("HYZK", 1, 1);
        model.addAttribute("maritalStatus", maritalStatus);
        model.addAttribute("user", userEntity);
        model.addAttribute("detailType", detailType);
        //查节点
        List<Map> nodelist = productNodeService.queryNodeListByProductOrderId(scOrderId, order.getNodeFlowId(), order.getVersion());
        logger.info("详情节点数据：》》》》》》》》》》"+JSONObject.toJSONString(nodelist));
        if (nodelist != null && nodelist.size() > 0) {
            Long nextNode = productNodeService.nextNodeOverTime(nodelist, order);
            model.addAttribute("nextNodeOverTime", nextNode);
            model.addAttribute("nodelist", nodelist);
        }
        if(flag){
            return "rzsc/order/order_detail_qdb";
        }
        return "rzsc/order/order_detail";
    }

    /**
     * 历史记录页面
     *
     * @param scOrderId
     * @param flowId
     * @param model
     * @return
     */
    @RequestMapping("/history_index")
    public String histortIndex(Long scOrderId, Long flowId, String detailType, Model model) {

        ProductOrder order = productOrderDao.selectByPrimaryKey(scOrderId);
        List<ProductNode> productNodes = productNodeService.queyNodeListByFlowIdAndVersion(flowId,order);
        List<Map> allRemarksNodeList = productNodeService.queryNodeAndRemarksNode(flowId,order);
        model.addAttribute("order", order);
        model.addAttribute("scOrderId", scOrderId);
        model.addAttribute("productNodes", productNodes);
        model.addAttribute("allRemarksNodeList", allRemarksNodeList);
        model.addAttribute("detailType", detailType);
        return "rzsc/order/order_history";
    }

    /**
     * 查询历史记录
     *
     * @param params
     * @return
     */
    @RequestMapping("/get_history")
    @ResponseBody
    public DggRestResponse getHistory(@RequestParam Map params) {
        try {
            List<ProductNodeOperating> list = productNodeOperatingDao.queryProductOperatingWithPage(params);
            return new DataTableResponse().data(params, list);
        } catch (Exception e) {
            e.printStackTrace();
            return new DataTableResponse().data(params, null);
        }
    }

    /**
     * 生产 详情里面保存节点备注
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/save_product_operating_by_detail")
    @ResponseBody
    public Object saveProductOperatingByDetail(@RequestParam Map params) {
        try {
            productNodeService.saveProductOperatingByDetail(params);
            return this.getSuccessResponse("操作成功!");
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 生产人员页面
     *
     * @param params
     * @param model
     * @return
     */
    @RequestMapping("/assist_info")
    public String assistInfo(@RequestParam Map params, Model model) {
        try {
            if (StringUtils.isNotEmpty(params.get("scorderId"))) {
                Long id = Long.valueOf(params.get("scorderId").toString());
                List<Assistant> flowUserList = productNodeService.queyScAssistantList(id);
                ProductOrder order = productOrderDao.selectByPrimaryKey(id);
                model.addAttribute("order", order);
                //构建查询日志条件
                Map<String, Object> map = new HashMap<>();
                map.put("source", 2);
                map.put("workId", id);
                int[] operateTypeArr = {1, 5, 9, 12, 13, 10, 15, 16};
                map.put("operateTypeArr", operateTypeArr);
                List<SystemRecord> recordsUserList = systemRecordService.findByParamsWithPage(map);
                model.addAttribute("flowUserList", flowUserList);
                model.addAttribute("recordsUserList", recordsUserList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "rzsc/order/assist_info";
    }

    /**
     * 附件页面
     *
     * @param productOrderId
     * @param model
     * @return
     */
    @RequestMapping(value = "/query_product_attachment_page")
    public String queryProductAttachment(Long productOrderId, Model model) {
        ProductOrder productOrder = productOrderService.selectByPrimaryKey(productOrderId);
        model.addAttribute("productOrderId", productOrderId);
        model.addAttribute("user", sessionManager.getCurrentUser());
        model.addAttribute("order", productOrder);
        return "rzsc/order/query_product_attachment_page";
    }

    /**
     * 业务信息页面
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/production_people_index")
    public String productionPeopleIndex(String orderNo, String scOrderId, Model model) {
        UserEntity userEntity = sessionManager.getCurrentUser();
        model.addAttribute("userEntitys", userEntity);
        try {
            ProductOrder productOrder = productOrderDao.selectByPrimaryKey(Long.parseLong(scOrderId));
            model.addAttribute("productOrderFlowUserId", productOrder.getFlowUserId());
        } catch (Exception e) {
            e.printStackTrace();
        }

        //客户信息
        OrderCustomer customer = orderCustomerDao.selectByOrderNo(orderNo);
        if (customer != null) {
            model.addAttribute("customerPhone", customer.getCustomerPhone());
            customer.setSex(translateUtil.translateCode(customer.getSex()));
            customer.setMaritalStatus(translateUtil.translateCode(customer.getMaritalStatus()));
            customer.setEduBackground(translateUtil.translateCode(customer.getEduBackground()));
            customer.setCustomerPhone(desUtil.decrypt(customer.getCustomerPhone()));//解密电话号码
            customer = CustomerNumberEncryptionUtil.encryptionObject(new String[]{"customerPhone"}, customer);//隐藏电话号码
            //隐藏身份号码
            customer.setIdCard(IdCardUtil.hiddenIdCard(customer.getIdCard()));

            model.addAttribute("customer", customer);
        }
        //合同约定
        OrderJsonDto json = orderJsonDao.selectByOrderNoDto(orderNo);
        if (json != null) {
            json.setLoansRateType(translateUtil.translateCode(json.getLoansRateType()));
            model.addAttribute("orderJson", json);
        }
        //成本费
        List<OrderSubject> orderSubjectList = orderSubjectDao.getListByOrderNo(orderNo);
        if (orderSubjectList != null && orderSubjectList.size() > 0) {
            orderSubjectList = translateUtil.translateList(new String[]{"subjectType"}, orderSubjectList);
            model.addAttribute("orderSubjectList", orderSubjectList);
        }
        return "rzsc/order/production_people";
    }

    /**
     * 根据客户ID获取身份证号码
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/get_customerCard_by_id")
    @ResponseBody
    public DggRestResponse getCustomerCardById(String id) {
        try {
            return this.getSuccessResponse(productOrderService.getCustomerCardById(id));
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * /**
     * 生产数据-抵押贷款页面
     *
     * @param productOrderId
     * @param model
     * @return
     */
    @RequestMapping(value = "/order_info_dydk")
    public String orderInfoDydk(Long productOrderId, Model model) {
        this.orderInfo(productOrderId, model);
        return "rzsc/order/order_info_dydk";
    }

    /**
     * 生产数据-信用贷款页面
     *
     * @param productOrderId
     * @param model
     * @return
     */
    @RequestMapping(value = "/order_info_xydk")
    public String orderInfoXydk(Long productOrderId, Model model) {
        this.orderInfo(productOrderId, model);
        return "rzsc/order/order_info_xydk";
    }

    /**
     * 生产数据-资金业务页面
     *
     * @param productOrderId
     * @param model
     * @return
     */
    @RequestMapping(value = "/order_info_zjyw")
    public String orderInfoZjyw(Long productOrderId, Model model) {
        this.orderInfo(productOrderId, model);
        return "rzsc/order/order_info_zjyw";
    }

    /**
     * 生产数据-其他页面
     *
     * @param productOrderId
     * @param model
     * @return
     */
    @RequestMapping(value = "/order_info_qt")
    public String orderInfoQt(Long productOrderId, Model model) {
        this.orderInfo(productOrderId, model);
        return "rzsc/order/order_info_qt";
    }

    /**
     * 生产数据-编辑后保存操作
     *
     * @param orderStr
     * @return
     */
    @RequestMapping(value = "/order_info_save")
    @ResponseBody
    public DggRestResponse orderInfoSave(String orderStr) {
        try {
            ProductOrder order = JsonUtil.json2Obj(orderStr, ProductOrder.class);
            //订单信息
            productOrderService.orderInfoSave(order);
            return this.getSuccessResponse("保存成功！");
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return this.getFailResponse("操作失败，请联系管理员");
        }
    }

    private void orderInfo(Long productOrderId, Model model) {
        ValidateUtils.strNotEmpty(productOrderId, CommonExcption.class, "生产子订单id不能为空");
        //订单信息
        ProductOrderDto order = productOrderDao.selectDtoByPrimaryKey(productOrderId);
        order.setWayOfLoanName(translateUtil.translateCode(order.getWayOfLoan()));
        order.setRateTypeName(translateUtil.translateCode(order.getRateType()));
        model.addAttribute("order", order);
        UserEntity userEntity = sessionManager.getCurrentUser();// 当前操作人
        model.addAttribute("user", userEntity);
        //查节点
        List<Map> nodelist = productNodeService.queryNodeListByProductOrderId(productOrderId, order.getNodeFlowId(), order.getVersion());
        if (nodelist != null && nodelist.size() > 0) {
            Long nextNode = productNodeService.nextNodeOverTime(nodelist, order);
            model.addAttribute("nextNodeOverTime", nextNode);
            model.addAttribute("nodelist", nodelist);
        }
        model.addAttribute("fileType", "refund");
        boolean isEdit = roleService.exitsOperate4User(userEntity.getId(),ScProductConstant.RZSC_OPERATION_EDIT);
        boolean orderStatus = ScProductConstant.RZSCORDER_STATUS19.equals(order.getStatus()) || ScProductConstant.RZSCORDER_STATUS20.equals(order.getStatus()) || ScProductConstant.RZSCORDER_STATUS17.equals(order.getStatus());
        if((userEntity.getId().equals(order.getFlowUserId()) && !orderStatus)||isEdit){
            model.addAttribute("isEdit", true);
        }
    }

    /**
     * 修改借贷人信息
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/order_contact_update")
    @ResponseBody
    public DggRestResponse orderContactUpdate(@RequestParam Map params) {
        try {
            productOrderService.orderContactUpdate(params);
            return this.getSuccessResponse("保存成功");
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 根据借贷人ID获取身份证号码
     *
     * @param contactId
     * @return
     */
    @GetMapping(value = "/get_IdCard_by_contactId")
    @ResponseBody
    public DggRestResponse getIdCardByContactId(String contactId) {
        try {
            return this.getSuccessResponse(productOrderService.getIdCardByContactId(contactId));
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * 根据借贷人ID获联系电话
     *
     * @param contactId
     * @return
     */
    @GetMapping(value = "/get_phone_by_contactId")
    @ResponseBody
    public DggRestResponse getPhoneyContactId(String contactId) {
        try {
            return this.getSuccessResponse(productOrderService.getPhoneByContactId(contactId));
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * @Author sdx
     * 工作录入-页面
     * @param scOrderId
     * @return
     */
    @RequestMapping("/work_entry")
    public String workEntry(@RequestParam Long scOrderId, @RequestParam Integer recordType ,Model model) {
        WorkLoadDto workLoadDto = productOrderWorkLoadService.findModel(scOrderId,null,recordType);
        if(null != workLoadDto){
            model.addAttribute("userEntity",workLoadDto.getUserEntity());
            model.addAttribute("order",workLoadDto.getOrder());
            if(!CollectionUtils.isEmpty(workLoadDto.getBlqyList())){
                model.addAttribute("blqyList",workLoadDto.getBlqyList());
            }
            if(!CollectionUtils.isEmpty(workLoadDto.getBllxList())){
                model.addAttribute("bllxList",workLoadDto.getBllxList());
            }
        }
        if(recordType == 1){
            return "rzsc/order/card_work_entry";
        }else if(recordType == 2){
            return "rzsc/order/information_work_entry";
        }else if(recordType == 3){
            return "rzsc/order/assessment_work_entry";
        }else{
            return "rzsc/order/stationary_point_work_entry";
        }
    }

    /**
     * @Author sdx
     * 工作录入-操作
     * @param recordType  录入类型
     * @param userId  操作人ID
     * @param scOrderId  生产订单ID
     * @param orgId  当前生产单生产所属事业部ID
     * @param pofwlJson  工作量录入JSON数据
     * @return
     */
    @RequestMapping(value = "/work_entry_add")
    @ResponseBody
    public DggRestResponse workEntryAdd(@RequestParam Long recordType, @RequestParam Long userId, @RequestParam Long scOrderId, @RequestParam Long orgId, @RequestParam String pofwlJson ) {
        try {
            productOrderWorkLoadService.addFieldWorkLoad(recordType, userId, scOrderId, orgId, pofwlJson);
            return this.getSuccessResponse("保存成功");
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }

    /**
     * @Author sdx
     * 外勤工作量数据-页面
     * @return
     */
    @RequestMapping("/field_work_load_data")
    public String fieldWorkLoadData(Model model) {
        model.addAttribute("recordType",1L);
        return "rzsc/order/field_work_load_data";

    }

    /**
     * @Author sdx
     * 外勤工作量数据-列表数据
     * @param params
     * @return
     */
    @RequestMapping("/field_work_load_data_list")
    @ResponseBody
    public DggRestResponse fieldWorkLoadDataList(@RequestParam Map params) {
        try {
            List<ProductOrderFieldWorkLoad> productOrderFieldWorkLoad = productOrderWorkLoadService.findProductOrderFieldWorkLoadWithPage(params);
            return new DataTableResponse().data(params,productOrderFieldWorkLoad);
        }catch (ProductOrderExcption e){
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            ExceptionUtils.error(e, PATH_PREFIX+"/field_work_load_data_list.do", params.toString());
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }

    }

    /**
     * @Author sdx
     * 工作录入记录编辑-页面
     * @return
     */
    @RequestMapping("/work_entry_update_page")
    public String workEntryUpdatePage(Long id,Model model) {
        WorkLoadDto workLoadDto = productOrderWorkLoadService.findProductOrderFieldWorkLoad(id,null);
        if(null != workLoadDto){
            model.addAttribute("userEntity",workLoadDto.getUserEntity());
            model.addAttribute("order",workLoadDto.getOrder());
            model.addAttribute("workEntry", workLoadDto.getProductOrderFieldWorkLoad());
            if(!CollectionUtils.isEmpty(workLoadDto.getBlqyList())){
                model.addAttribute("blqyList",workLoadDto.getBlqyList());
            }
            if(!CollectionUtils.isEmpty(workLoadDto.getBllxList())){
                model.addAttribute("bllxList",workLoadDto.getBllxList());
            }
        }
        return "rzsc/order/work_entry_update";
    }

    /**
     * @Author sdx
     * 工作录入记录编辑-操作
     * @param pofwlJson  工作量录入JSON数据
     * @return
     */
    @RequestMapping(value = "/work_entry_update")
    @ResponseBody
    public DggRestResponse workEntryUpdate(@RequestParam String pofwlJson ) {
        try {
            productOrderWorkLoadService.updateFieldWorkLoad(null,pofwlJson);
            return this.getSuccessResponse("保存成功");
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }


    /**
     * @Author sdx
     * 工作录入记录删除-操作
     * @param id  工作量记录ID
     * @return
     */
    @RequestMapping(value = "/work_entry_delete")
    @ResponseBody
    public DggRestResponse workEntryDelete(@RequestParam Long id ) {
        try {
            productOrderWorkLoadService.deleteFieldWorkLoad(null, id);
            return this.getSuccessResponse("删除成功");
        } catch (CommonExcption e) {
            e.printStackTrace();
            return this.getFailResponse(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return this.getFailResponse(ScProductConstant.SYS_ERROR);
        }
    }
    /**
     * @Author sdx
     * 导出(全部)
     */
    @RequestMapping(value = "excel_export_all")
    @ResponseBody
    @SuppressWarnings("all")
    public void exportDetailExcelAll(@RequestParam Map params) {
        dataPermissionUtils.flowUserDataAccess(params, ModuleCodeConstant.RZSC_ALLO_WORK_LOAD_CODE);
        List<ProductOrderFieldWorkLoad> list = productOrderWorkLoadService.findProductOrderFieldWorkLoadWithPage(params);
        //TODO 序列化时间格式为日期格式，驻点人员工作量与其他工作量需要转换的字段不一样,需区别转换
        if(Long.parseLong(params.get("recordType").toString()) == 4L){
            for(ProductOrderFieldWorkLoad map : list){
               String time = DggDateUtil.format(map.getLoanTime(),"yyyy-MM-dd");
               map.setStrTime(time);
            }
        }else{
            for(ProductOrderFieldWorkLoad map : list){
                String time = DggDateUtil.format(map.getHandleTime(),"yyyy-MM-dd");
                map.setStrTime(time);
            }
        }
        //TODO 导出工作量分四种情况
        int[] widths = null;
        int[] styleArr = null;
        String[] title = null;
        String[] keyArray = null;
        String sheetName  = null;
        //权证人员工作量
        if(Long.parseLong(params.get("recordType").toString()) == 1L){
            sheetName  ="权证工作量数据";
            widths = new int[] { 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
            styleArr = new int[] { -1,-1,-1, 1, 1, 0 , 1, 1, 1, 1, 0,1};
            title = new String[]{"订单编号","生产订单编号","客户","生产状态","流程人员","办理人员","办理类型","办理区域","办理地点","办理日期","生产事业部","备注"};
            keyArray = new String[] {"orderNo", "scProductOrderNo", "customerName","status","flowUserName","manageUserName","handleTypeValue","handleAreaValue","handlePlace","strTime","productOrgName","remark"};
        }
        //资料人员工作量
        if(Long.parseLong(params.get("recordType").toString()) == 2L){
            sheetName  ="资料工作量数据";
            widths = new int[] { 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
            styleArr = new int[] { -1,-1,-1, 1, 1, 0 , 1, 1, 1, 1, 0,1};
            title = new String[]{"订单编号","生产订单编号","客户","生产状态","流程人员","办理人员","银行","办理类型","办理数量","办理日期","生产事业部","备注"};
            keyArray = new String[] {"orderNo", "scProductOrderNo", "customerName","status","flowUserName","manageUserName","bank","handleTypeValue","handleNum","strTime","productOrgName","remark"};
        }
        //评估人员工作量
        if(Long.parseLong(params.get("recordType").toString()) == 3L){
            sheetName  ="评估工作量数据";
            widths = new int[] { 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
            styleArr = new int[] { -1,-1, 1, 1, 0 , 1, 1, 1, 1, 0,1};
            title = new String[]{"订单编号","生产订单编号","客户","生产状态","流程人员","办理人员","银行","评估公司","办理日期","生产事业部","备注"};
            keyArray = new String[] {"orderNo", "scProductOrderNo", "customerName","status","flowUserName","manageUserName","bank","assessmentCompany","strTime","productOrgName","remark"};
        }
        //驻点人员工作量
        if(Long.parseLong(params.get("recordType").toString()) == 4L){
            sheetName  ="驻点工作量数据";
            widths = new int[] { 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8, 512*8};
            styleArr = new int[] { -1,-1, 1, 1, 0 , 1, 1, 1, 1, 0,1};
            title = new String[]{"订单编号","生产订单编号","客户","生产状态","流程人员","办理人员","渠道","放款金额","放款日期","生产事业部","备注"};
            keyArray = new String[] {"orderNo", "scProductOrderNo", "customerName","status","flowUserName","manageUserName","channelName","loanMoney","strTime","productOrgName","remark"};
        }
        ExcelTool.execlExport(list,sheetName,title,keyArray,widths,styleArr);
    }
}
